home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Demos / AppMaker 2.0b3 / Demo AppMaker 2.0b3 / Examples / pre-built AMReminder / PowerPlant / CAMReminderDoc.cp < prev    next >
Encoding:
Text File  |  1995-10-05  |  5.6 KB  |  277 lines  |  [TEXT/MMCC]

  1. // CAMReminderDoc.cp -- Document methods
  2. // Created 10/5/95 4:49 PM by AppMaker
  3.  
  4. #include "CAMReminderDoc.h"
  5.  
  6. #include "CAMReminderData.h"
  7. #include "CMainWindow.h"
  8. #include "CmdCodes.h"
  9. #include "CAdd.h"
  10.  
  11. #include <LFile.h>
  12. #include <LPlaceHolder.h>
  13. #include <LPrintout.h>
  14. #include <LWindow.h>
  15. #include <UWindows.h>
  16. #include <String_Utils.h>
  17.  
  18. const ResIDT    prto_PrintView        = 201;
  19. const ResIDT    STRx_Untitled        = 128;
  20.  
  21. // ---------------------------------------------------------------------------
  22. //        • CAMReminderDoc
  23. // ---------------------------------------------------------------------------
  24.  
  25. CAMReminderDoc::CAMReminderDoc(
  26.     LCommander    *inSuper)
  27.         : LSingleDoc(inSuper)
  28. {
  29.     mData = new CAMReminderData();
  30. }
  31.  
  32. // ---------------------------------------------------------------------------
  33. //        • ~CAMReminderDoc
  34. // ---------------------------------------------------------------------------
  35. //    Destructor
  36. //
  37.  
  38. CAMReminderDoc::~CAMReminderDoc()
  39. {
  40.     delete mData;
  41. }
  42.  
  43. //----------
  44. void
  45. CAMReminderDoc::newFile()
  46. {
  47.     mData->newData();
  48.  
  49.     MakeWindows();
  50.  
  51.     NameNewDoc();        // Set name of untitled window
  52. }
  53.  
  54. //----------
  55. void
  56. CAMReminderDoc::openFile(
  57.     FSSpec        *inFileSpec)
  58. {
  59.     mData->openData (inFileSpec);
  60.  
  61.     MakeWindows();
  62.  
  63.     if (mWindow != nil) {
  64.         mWindow->SetDescriptor (inFileSpec->name);
  65.     }
  66.     mIsSpecified = true;
  67. }
  68.  
  69. // ---------------------------------------------------------------------------
  70. //        • MakeWindows
  71. // ---------------------------------------------------------------------------
  72.  
  73. void
  74. CAMReminderDoc::MakeWindows()
  75. {
  76.     mMainWindow = CMainWindow::CreateMainWindow(this, mData);
  77.  
  78.     mWindow = mMainWindow;
  79. }
  80.  
  81. // ---------------------------------------------------------------------------
  82. //        • NameNewDoc
  83. // ---------------------------------------------------------------------------
  84. //    Name a new, untitled document window
  85. //
  86. //    Untitled windows start with "untitled", then "untitled 1",
  87. //    "untitled 2", etc. Old numbers are reused, so there won't be
  88. //    gaps in the numbering.
  89. //
  90. //    This routine uses a STR# resource to store the "untitled" string,
  91. //    which can be localized to different languages. The first string
  92. //    is "untitled" and the second is "untitled " (trailing space),
  93. //    which is used when appending a number to the name.
  94.  
  95. void
  96. CAMReminderDoc::NameNewDoc()
  97. {
  98.         // Start with the default name("untitled")
  99.     Str255    name;
  100.     ::GetIndString(name, STRx_Untitled, 1);
  101.  
  102.     long    num = 0;
  103.     while (UWindows::FindNamedWindow(name) != nil) {
  104.  
  105.             // An existing window has the current name
  106.             // Increment counter and try again
  107.  
  108.         ::GetIndString(name, STRx_Untitled, 2);
  109.         num++;
  110.         Str15    numStr;
  111.         ::NumToString(num, numStr);
  112.         ConcatPStr(name, numStr);
  113.     }
  114.  
  115.     mWindow->SetDescriptor(name);        // Finally, set window title
  116. }
  117.  
  118. // ---------------------------------------------------------------------------
  119. //        • IsModified
  120. // ---------------------------------------------------------------------------
  121. //    Return whether the Document has changed since the last save
  122.  
  123. Boolean
  124. CAMReminderDoc::IsModified()
  125. {
  126.     mIsModified = mData->IsDirty();
  127.  
  128.     return mIsModified;
  129. }
  130.  
  131. // ---------------------------------------------------------------------------
  132. //        • DoAESave
  133. // ---------------------------------------------------------------------------
  134. //    Save Document in the specified file with the specified file type
  135. //
  136. //    If file type is fileType_Default, use the normal file type for
  137. //    this document
  138.  
  139. void
  140. CAMReminderDoc::DoAESave(
  141.     FSSpec    &inFileSpec,
  142.     OSType    inFileType)
  143. {
  144.     mData->DoSaveAs(&inFileSpec);                // Write out data
  145.                                         // Change window name
  146.     mWindow->SetDescriptor(inFileSpec.name);
  147. }
  148.  
  149. //----------
  150. void
  151. CAMReminderDoc::DoSave()
  152. {
  153.     mData->DoSave();
  154. }
  155.  
  156. //----------
  157. void
  158. CAMReminderDoc::DoRevert()
  159. {
  160.     mData->DoRevert();
  161. }
  162.  
  163. // ---------------------------------------------------------------------------
  164. //        • DoPrint
  165. // ---------------------------------------------------------------------------
  166. //    Print the contents of the Document
  167.  
  168. void
  169. CAMReminderDoc::DoPrint()
  170. {
  171.     LPrintout        *thePrintout = LPrintout::CreatePrintout(prto_PrintView);
  172.     LPlaceHolder    *textPlace = (LPlaceHolder *)
  173.                                     thePrintout->FindPaneByID('TBox');
  174. //!    textPlace->InstallOccupant(mTextView, atNone);
  175.  
  176.  
  177.     thePrintout->DoPrintJob();
  178.     delete thePrintout;
  179. }
  180.  
  181. //----------
  182. void
  183. CAMReminderDoc::DoAddReminder ()
  184. {
  185. CAdd*    dialog = CAdd::CreateAdd(this);
  186. }
  187.  
  188. //----------
  189. void
  190. CAMReminderDoc::DoEditReminder ()
  191. {
  192. CAdd*    dialog = CAdd::CreateAdd(this);
  193. }
  194.  
  195. //----------
  196. void
  197. CAMReminderDoc::DoDeleteReminder ()
  198. {
  199. }
  200.  
  201. //----------
  202. void
  203. CAMReminderDoc::ObeyAdd    (void*    ioParam)
  204. {
  205. }
  206.  
  207. //----------
  208. Boolean
  209. CAMReminderDoc::ObeyCommand(
  210.     CommandT    inCommand,
  211.     void        *ioParam)
  212. {
  213.     Boolean        cmdHandled = true;
  214.  
  215.     switch (inCommand) {
  216.  
  217.     // +++ Add cases here for the commands you handle
  218.     //        Remember to add same cases to FindCommandStatus below
  219.     //        to enable/disable the menu items for the commands
  220.  
  221.  
  222.     case cmdAddReminder:
  223.         DoAddReminder ();
  224.         break;
  225.  
  226.     case cmdEditReminder:
  227.         DoEditReminder ();
  228.         break;
  229.  
  230.     case cmdDeleteReminder:
  231.         DoDeleteReminder ();
  232.         break;
  233.  
  234.     case cmd_Add:
  235.         ObeyAdd    (ioParam);
  236.         break;
  237.  
  238.     default:
  239.             cmdHandled = LSingleDoc::ObeyCommand(inCommand, ioParam);
  240.         break;
  241.     }
  242.  
  243.     return cmdHandled;
  244. }
  245.  
  246. //----------
  247. void
  248. CAMReminderDoc::FindCommandStatus(
  249.     CommandT    inCommand,
  250.     Boolean        &outEnabled,
  251.     Boolean        &outUsesMark,
  252.     Char16        &outMark,
  253.     Str255        outName)
  254. {
  255.     outUsesMark = false;
  256.  
  257.     switch (inCommand) {
  258.  
  259.     // +++ Add cases here for the commands you handle
  260.  
  261.     case cmdAddReminder:
  262.         outEnabled = true;
  263.         break;
  264.     case cmdEditReminder:
  265.         outEnabled = true;
  266.         break;
  267.     case cmdDeleteReminder:
  268.         outEnabled = true;
  269.         break;
  270.  
  271.     default:
  272.             LSingleDoc::FindCommandStatus(inCommand, outEnabled,
  273.                                             outUsesMark, outMark, outName);
  274.         break;
  275.     }
  276. }
  277.